package pcjavanet.mobilesell.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import pcjavanet.mobilesell.model.ExeclMobile;
import pcjavanet.mobilesell.model.Member;
import pcjavanet.mobilesell.model.PageBean;
import pcjavanet.mobilesell.model.QryCondition;
import pcjavanet.mobilesell.service.ExeclMobileService;
import pcjavanet.mobilesell.service.MemberService;

import com.opensymphony.xwork2.ActionSupport;
@Namespace("/execlMobile")
@Controller
@Scope("prototype")
@ParentPackage("json-default")
@Results({
	@Result(name = "success", location = "/view/ExeclMobile.jsp"),
	@Result(name = "input", location = "/view/ExeclMobile.jsp")
})

public class ExeclMobileAction  extends ActionSupport {

		@Resource
	  private ExeclMobileService execlMobileService;
	  @Resource
	  private MemberService memberService;
	  private   java.lang.Integer dbid ;
	  private   java.lang.Integer refStorehouseDbid ;
	  private   java.lang.Integer customerid ;
	  private   java.lang.String brand ;
	  private   java.lang.String type ;
	  private   java.lang.String serial ;
	  private   java.lang.String color ;
	  private   java.lang.Double price ;
	  private   java.util.Date buydate ;
	  private   java.lang.String itemtype ;
	  private   java.lang.String mobile ;
	  private int start  ;
	  private int limit  ;
	  private int totalProperty  ;
	  private int limitNumber;
	  private boolean displayRecord;
	  private boolean success = true ;
	  private String  info ;
	  private List<ExeclMobile>  execlMobilePageBeans  ;
	  public    java.lang.Integer getDbid() {
	   	return this.dbid;
	  }
	  public java.lang.String getMobile() {
		return mobile;
	}
	public void setMobile(java.lang.String mobile) {
		this.mobile = mobile;
	}
	public boolean isDisplayRecord() {
		return displayRecord;
	}
	public void setDisplayRecord(boolean displayRecord) {
		this.displayRecord = displayRecord;
	}
	public java.lang.Integer getRefStorehouseDbid() {
		return refStorehouseDbid;
	}
	public void setRefStorehouseDbid(java.lang.Integer refStorehouseDbid) {
		this.refStorehouseDbid = refStorehouseDbid;
	}
	public int getLimitNumber() {
		return limitNumber;
	}
	public void setLimitNumber(int limitNumber) {
		this.limitNumber = limitNumber;
	}
	public void setDbid(  java.lang.Integer  dbid) {
   	 this.dbid=dbid;
  }
  public    java.lang.Integer getCustomerid() {
   	return this.customerid;
  }
  public void setCustomerid(  java.lang.Integer  customerid) {
   	 this.customerid=customerid;
  }
  public    java.lang.String getBrand() {
   	return this.brand;
  }
  public void setBrand(  java.lang.String  brand) {
   	 this.brand=brand;
  }
  public    java.lang.String getType() {
   	return this.type;
  }
  public void setType(  java.lang.String  type) {
   	 this.type=type;
  }
  public    java.lang.String getSerial() {
   	return this.serial;
  }
  public void setSerial(  java.lang.String  serial) {
   	 this.serial=serial;
  }
  public    java.lang.String getColor() {
   	return this.color;
  }
  public void setColor(  java.lang.String  color) {
   	 this.color=color;
  }
  public    java.lang.Double getPrice() {
   	return this.price;
  }
  public void setPrice(  java.lang.Double  price) {
   	 this.price=price;
  }
  public    java.util.Date getBuydate() {
   	return this.buydate;
  }
  public void setBuydate(  java.util.Date  buydate) {
   	 this.buydate=buydate;
  }
  public    java.lang.String getItemtype() {
   	return this.itemtype;
  }
  public void setItemtype(  java.lang.String  itemtype) {
   	 this.itemtype=itemtype;
  }
  public  void setStart(int start) {
   	 this.start = start;
  }
  public  void setLimit(int limit) {
   	 this.limit = limit;
  }
  public  void setTotalProperty(int totalProperty) {
   	 this.totalProperty = totalProperty;
  }
  public  void setExeclMobilePageBeans(List<ExeclMobile> execlMobilePageBeans){
   	 this.execlMobilePageBeans =execlMobilePageBeans  ;
  }
  public  int getStart( ) {
   	 return this.start;
  }
  public  int getLimit( ) {
   	 return this.limit;
  }
  public  int getTotalProperty( ) {
   	 return this.totalProperty;
  }
  public    List<ExeclMobile> getExeclMobilePageBeans(){
   	 return this.execlMobilePageBeans   ;
  }
  public  String getInfo( ) {
   	 return this.info;
  }
  public  void setInfo(String info){
   	 this.info = info ;
  }
  public  boolean getSuccess( ) {
   	 return this.success;
  }
  public  void setSuccess(boolean success){
   	 this.success = success ;
  }

  @Action(value="insertExeclMobile",results = {@Result(name = "success", type = "json")})
  public String  insertExeclMobile() throws Exception{
   	success = false ;
   	info = "" ;
   	Member m = new Member();
   	m.setMobile(mobile);
   	List<Member>	 ms = memberService.selectByExample( m );
    if ( ms.size() > 0 ) {
    	m = ms.get(0);
    	Integer customerId = m.getDbid();
	  	ExeclMobile bean = new ExeclMobile();
	  	bean.setCustomerid(customerId);
	  	bean.setMobile(mobile);
	  	bean.setRefStorehouseDbid(refStorehouseDbid);
	  	bean.setCustomerid(this.customerid); 
	  	bean.setBrand(this.brand); 
	  	bean.setType(this.type); 
	  	bean.setSerial(this.serial); 
	  	bean.setColor(this.color); 
	  	bean.setPrice(this.price); 
	  	bean.setBuydate(this.buydate); 
	  	bean.setItemtype(this.itemtype); 
	  	bean.setName( m.getName() );
		execlMobileService.insert(bean);
	   	success = true ;
	   	info = "Add Successful" ;
    } else {
       	success = false ;
       	info = "Add fail" ;
    }
   	return SUCCESS;
  }

  @Action(value="queryExeclMobile",results = {@Result(name = "success", type = "json")})
  public String  queryExeclMobile() throws Exception{
  	ExeclMobile bean = new ExeclMobile();
  	bean.setRefStorehouseDbid(refStorehouseDbid);
  	bean.setDbid(this.dbid); 
  	bean.setCustomerid(this.customerid); 
  	bean.setBrand(this.brand); 
  	bean.setType(this.type); 
  	bean.setSerial(this.serial); 
  	bean.setColor(this.color); 
  	bean.setPrice(this.price); 
  	bean.setBuydate(this.buydate); 
  	bean.setItemtype(this.itemtype); 
	execlMobileService.selectByPrimaryKey(bean);
   	return SUCCESS;
  }

  @Action(value="updateExeclMobile",results = {@Result(name = "success", type = "json")})
  public String  updateExeclMobile() throws Exception{
   	success = false ;
   	info = "" ;
  	ExeclMobile bean = new ExeclMobile();
  	bean.setRefStorehouseDbid(refStorehouseDbid);
  	bean.setRefStorehouseDbid(refStorehouseDbid);
  	bean.setDbid(this.dbid); 
  	bean.setCustomerid(this.customerid); 
  	bean.setBrand(this.brand); 
  	bean.setType(this.type); 
  	bean.setSerial(this.serial); 
  	bean.setColor(this.color); 
  	bean.setPrice(this.price); 
  	bean.setBuydate(this.buydate); 
  	bean.setItemtype(this.itemtype); 
  	bean =execlMobileService.selectByPrimaryKey(bean);
  	bean.setRefStorehouseDbid(refStorehouseDbid);
  	bean.setDbid(this.dbid); 
  	bean.setCustomerid(this.customerid); 
  	bean.setBrand(this.brand); 
  	bean.setType(this.type); 
  	bean.setSerial(this.serial); 
  	bean.setColor(this.color); 
  	bean.setPrice(this.price); 
  	bean.setBuydate(this.buydate); 
  	bean.setItemtype(this.itemtype); 
	execlMobileService.updateByPrimaryKeySelective(bean);
   	success = true ;
   	info = "Update Successful" ;
   	return SUCCESS;
  }

  @Action(value="deleteExeclMobile",results = {@Result(name = "success", type = "json")})
  public String  deleteExeclMobile() throws Exception{
  	ExeclMobile bean = new ExeclMobile();
  	bean.setRefStorehouseDbid(refStorehouseDbid);
  	bean.setDbid(this.dbid); 
  	bean.setCustomerid(this.customerid); 
  	bean.setBrand(this.brand); 
  	bean.setType(this.type); 
  	bean.setSerial(this.serial); 
  	bean.setColor(this.color); 
  	bean.setPrice(this.price); 
  	bean.setBuydate(this.buydate); 
  	bean.setItemtype(this.itemtype); 
	execlMobileService.deleteByPrimaryKey(bean);
   	return SUCCESS;
  }

  @Action(value="listExeclMobile",results = {@Result(name = "success", type = "json")})
  public String  listExeclMobile() throws Exception{
 	QryCondition qry = RequestUtil.getQryCondition(   (javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST)); 	PageBean pageBean = new PageBean();
	pageBean.setPageSize( limit );
	pageBean.setStartCount( start );
	totalProperty =execlMobileService.getTotalRecords( qry, pageBean );
	execlMobilePageBeans =execlMobileService.getOnePageBeans( qry, pageBean );
   	return SUCCESS;
  }
  
  @Action(value="listTopExeclMobile",results = {@Result(name = "success", type = "json")})
  public String  listTopExeclMobile() throws Exception{
	  QryCondition qry = RequestUtil.getQryCondition(   (javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST)); 	PageBean pageBean = new PageBean();
//	  pageBean.setPageSize( limit );
//	  pageBean.setStartCount( start );
//	  totalProperty =execlMobileService.getTotalRecords( qry, pageBean );
	  pageBean = new PageBean();
	  pageBean.setPageSize(limitNumber);
	  pageBean.setStartCount( start );
	  execlMobilePageBeans =execlMobileService.getTopBeans( qry, pageBean ,displayRecord);
	  return SUCCESS;
  }

  @Action("index")
  public String index() throws Exception{
   	return SUCCESS;
  }

}
